# -*- coding: utf-8 -*-
# @Time : 2022-01-06 9:00
# @Author : Z
# @Function :
from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By


class Web:

    def __init__(self, browser: str = 'gc'):
        if browser == 'gc':
            self.driver = webdriver.Chrome()
        elif browser == 'ff':
            self.driver = webdriver.Firefox()
        elif browser == 'ie':
            self.driver = webdriver.Ie()
        else:
            self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)

    def login(self, name: str = '', password: str = ''):
        self.driver.get('http://testingedu.com.cn:8000/index.php/Home/user/login.html')
        self.driver.find_element(By.XPATH, '//input[@id="username"]').send_keys(name)
        self.driver.find_element(By.XPATH, '//*[@id="password"]').send_keys(password)
        self.driver.find_element(By.XPATH, '//*[@id="verify_code"]').send_keys('1111')
        ele = self.driver.find_element(By.XPATH, '//*[@name="sbtbutton"]')
        self.driver.execute_script('arguments[0].click();', ele)
        sleep(1)

    def quit(self):
        self.driver.quit()


if __name__ == '__main__':
    web = Web('gc')
    web.login('13800138006', '1213456')
    web.login('13800138006', '123456')
    web.quit()
